package com.ash.select;

import com.ash.util.ConnectionUtil;

import java.sql.*;
import java.util.Objects;

/**
 * @encoding : UTF-8
 * @Time : 2020/12/3 17:03
 * @Author : Chen Chao
 * @File : connection.com.ash.select.Test02.java
 * @Software : IntelliJ IDEA
 * @since : 1.8
 * 查询记录
 */
public class Test02 {
    public static void main(String[] args) {
        Connection connection = ConnectionUtil.getConnection();
        Statement statement = null;
        ResultSet resultSet=null;
        /*3.创建sql语句*/
        String sql = "Select * from employee";
        try {
            /*4.创建sql语句执行对象*/
            statement = Objects.requireNonNull(connection).createStatement();
            /*5.执行sql语句，DML返回受影响行数*/
            resultSet = statement.executeQuery(sql);
            System.out.println("id  \t\tname\t\tgender" );
            while (resultSet.next()) {
                int id = resultSet.getInt("id");
                String name = resultSet.getString("name");
                String gender = resultSet.getString("gender");
                System.out.println(id+"\t\t"+name+"  \t\t"+gender);
            }
        } catch ( SQLException e) {
            e.printStackTrace();
        } finally {
            ConnectionUtil.close(connection,statement,resultSet);


        }
    }
}